/*
** 2853.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Fri Oct  3 14:29:48 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

/* #include "2853.h" */
#include <stdio.h>

int main()
{
     int instance, target, i;
     int n, sn, count;

     scanf("%d", &instance);
     while(instance){
	  scanf("%d %d", &i, &target);
	  for(n = 2, sn = 3, count = 0; sn <= target; n++, sn += n)
	       if ((target - sn) % n == 0)
		    count++;
	  printf("%d %d\n", i, count);
	  instance--;
     }
     return 0;
}

